<?php

$update		=	'update';
require_once('../Core/Common.php');
@header('Content-Type: text/html; charset=UTF-8');
if( $conf['version'] == Version ) {
    echo "<script language='javascript'>alert(您的数据库信息已是最新版:{$conf['version']},无需更新！');history.back();</script>";
}else{
    require './db.class.php';
    $sqls = file_get_contents(Version.'.sql');
    $sql=explode(';',$sqls);
	$cn = DB::connect($dbconfig['host'],$dbconfig['user'],$dbconfig['pwd'],$dbconfig['dbname'],$dbconfig['port']);
	if (!$cn) die('err:'.DB::connect_error());
	DB::query("set sql_mode = ''");
	DB::query("set names utf8");
	$t=0; $e=0; $error='';
	for($i=0;$i<count($sql);$i++) {
		if (trim($sql[$i])=='')continue;
		if(DB::query($sql[$i])) {
			++$t;
		} else {
			++$e;
			$error.=DB::error().'<br/>';
		}
	}
saveSetting('version',Version);
$CACHE->clear();
exit("<script language='javascript'>alert('网站数据库升级完成,已经更新到".Version."版的数据！');history.back();</script>");
}
?>